package persistencia;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Consultas {
	public static ResultSet obtenerHeroesMasUsados(Statement s, int tamanoLista) {
		ResultSet res = null;
		try {
			String query = "SELECT H.localized_name, H.name, COUNT( J.heroID ) AS VECES FROM jugadores J, heroes H, matches P WHERE J.playerID = 37233446 AND J.matchID = P.matchID AND P.gameMode != 7 AND P.gameMode != 9 AND H.heroID = J.heroID GROUP BY J.heroID ORDER BY VECES DESC LIMIT " + tamanoLista;
			
			res = s.executeQuery(query);
			System.out.println();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return res;
	}
	
	public static ResultSet highestGoldPerMin(Statement s, int tamanoLista){
		ResultSet res = null;
		
		try{
			String query = 
					"SELECT H.localized_name, J.gold_per_min, J.matchID " +
					"FROM jugadores J, heroes H, matches P " +
					"WHERE J.playerID = 37233446 " +
					"AND J.matchID = P.matchID " +
					"AND P.gameMode != 7 " +
					"AND P.gameMode != 9 " +
					"AND H.heroID = J.heroID " +
					"ORDER BY gold_per_min DESC LIMIT " + tamanoLista;
			
			res = s.executeQuery(query);
		}catch(SQLException e){
			e.printStackTrace();
		}
		
		return res;
	}

	public static Long ultimaPartida(Statement s) {
		ResultSet result = null;
		Long res = null;

		try {
			result = s
					.executeQuery("SELECT MAX(matchID) AS ultimaPartida FROM matches");

			if (result.next())
				res = result.getLong("ultimaPartida");
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return res;
	}
}
